/*
 ***** BEGIN LICENSE BLOCK *****
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations
 * under the License.
 *
 * The Original Code is BS1.
 *
 * The Initial Developer of the Original Code is SpaceMan.
 * Portions created by SpaceMan are Copyright (C) 2009
 * SpaceMan. All Rights Reserved.
 *
 * Contributor(s):
 * SpaceMan <sandaimespaceman@gmail.com>
 *
 * Alternatively, the contents of this file may be used under the terms
 * of the GNU Public License (the "GPL License"), in which case the
 * provisions of MPL License are applicable instead of those
 * above. If you wish to allow use of your version of this file only
 * under the terms of the GPL License and not to allow others to use
 * your version of this file under the MPL, indicate your decision by
 * deleting the provisions above and replace them with the notice and
 * other provisions required by the GPL License. If you do not delete
 * the provisions above, a recipient may use your version of this file
 * under either the MPL or the GPL License.
 ***** END LICENSE BLOCK *****
 */
package com.uniteduniverse.apps.BS1_CLI;

import java.io.*;

/**
 * BrainSpace1 useful functions.
 * @author SpaceMan
 * @version 1.0
 */
public class Util
{
	/**
	 * Get contents from a file.
	 * @param aFile The File
	 * @return The contents
	 * @throws java.io.FileNotFoundException
	 * @throws java.io.IOException
	 */
	static public String FileGetContents(File aFile) throws FileNotFoundException, IOException
	{
		//Code is copied from http://www.javapractices.com/topic/TopicAction.do?Id=42 which is licensed under CC BY 3.0
		StringBuilder contents = new StringBuilder();
		BufferedReader input = new BufferedReader(new FileReader(aFile));
		String line = null;

		while ((line = input.readLine()) != null)
		{
			contents.append(line);
			contents.append(System.getProperty("line.separator"));
		}
		input.close();

		return contents.toString();
	}

	/**
	 * Create string from one char code.
	 * @param c The char code
	 * @return The string based on the char code
	 */
	public static String StringFromCharCode(char c)
	{
		char[] dummy = new char[1];
		dummy[0] = c;
		return new String(dummy);
	}

	/**
	 * Scan for a string in a String array.
	 * @param arr The array to be scanned
	 * @param scan The string
	 * @return TRUE if there is a match
	 */
	public static boolean ScanStringFromArray(String[] arr, String scan)
	{
		for (String val : arr)
		{
			if (val.equals(scan))
			{
				return true;
			}
		}
		return false;
	}
}
